package com.xrit;


import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.util.HashMap;

/**
 * 类名称: FreeMarkerDemo
 * 类描述:FreeMarker的学习
 * 创建人: czb
 * 创建时间:2022/6/25 下午 04:19
 * Version 1.0.0
 */
public class FreeMarkerDemo {
    public static void main(String[] args) throws IOException, TemplateException {
        //"d:\\develop\\ftl"
        //创建对象
        Configuration configuration = new Configuration(Configuration.VERSION_2_3_23);
        //设置包
        configuration.setDirectoryForTemplateLoading(new File("d:\\develop\\ftl"));
        //处理乱码
        configuration.setDefaultEncoding("UTF-8");
        //获取模板
        Template template = configuration.getTemplate("test.ftl");
        //创建map
        HashMap<String, Object> map = new HashMap<>();
        map.put("name","张三");
        map.put("message","今天要看快乐星猫");
        //保存文件的路径
        Writer fileWriter = new FileWriter("d:\\develop\\test.html");
        //将数据填充到模板里
        template.process(map,fileWriter);
        //关闭
        fileWriter.close();
    }
}
